package com.dudu.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;

import com.dudu.bean.PushToCusRecordBean;
import com.dudu.dao.PushCallRecordDao;
import com.dudu.model.PushToCusRecord;
import com.dudu.service.IPushCallRecordService;
import com.dudu.utils.EnumUtility;

import core.CoreDao;
import core.CoreDaoInvoke;

public class PushCallRecordServiceimpl implements IPushCallRecordService {
	private CoreDao coreDao = CoreDaoInvoke.getInstance();
	private static final Logger log =  core.util.Logger.getLogger(PushCallRecordServiceimpl.class.getSimpleName());
	private PushCallRecordDao pushDao=new PushCallRecordDao();
	/**
	 * 根据拼接的查询条件查询推送失败的话单记录
	 * @param dao
	 * @param pageSql
	 * @param paramSql
	 * @return
	 */
	public List<PushToCusRecordBean> queryPushFailed(String pageSql,
			String paramSql) {
		log.info("PushCallRecordServiceImpl.queryPushFailed");
		List<PushToCusRecordBean> resultlist=new ArrayList<PushToCusRecordBean>();
		//后面所需返回的list
		List<PushToCusRecord> pushToCusRecord = new ArrayList<PushToCusRecord>();
		//开始查询账号信息
		pushToCusRecord=pushDao.queryPushFailed(coreDao, pageSql, paramSql);
		if(EnumUtility.isBlank(pushToCusRecord)){
			return null;
		}
		for(PushToCusRecord bean:pushToCusRecord){
			resultlist.add(conversion(bean));
		}
		return resultlist;
	}

	/**
	 * 获取推送失败的话单的条数
	 * @param paramSql
	 * @return
	 */
	public int getTotalFailedPush(String paramSql) {
		log.info("PushCallRecordServiceImpl.getTotalUnpush");
		int totalUnpush=-1;
		//查询总数量
		totalUnpush=pushDao.getTotalUnpush(coreDao, paramSql);
		return totalUnpush;
	}

	/**
	 * 向第三方重推话单：根据id，更改status状态为0；清空pid，note，code
	 * @param id
	 * @return
	 */
	public String repushCall(String id) {
		log.info("PushCallRecordServiceImpl.repushCall");
		String result="-1";
		//开始查询账号信息
		int isOK = pushDao.updateStatusPidNoteCode(coreDao, id);
		//如果返回的不是-1则说明update正常
		if(isOK!=-1){
			result = isOK + "";
		}
		return result;
	}
	/**
	 * 转化
	 * @param bean
	 * @return
	 */
	private PushToCusRecordBean conversion(PushToCusRecord bean){
		PushToCusRecordBean thisbean=new PushToCusRecordBean();
		BeanUtils.copyProperties(bean, thisbean);//源,目的
		//PropertyUtils.copyProperties(dest, orig);//目的,源
		return thisbean;
	}
	/**
	 * 转化
	 * @param menuBean
	 * @return
	 */
	private PushToCusRecord conversion(PushToCusRecordBean bean){
		PushToCusRecord thisbean=new PushToCusRecord();
		BeanUtils.copyProperties(bean,thisbean);//源,目的
		//PropertyUtils.copyProperties(dest, orig);//目的,源
		return thisbean;
	}
}
